<?php
include("Image/Graph.php");

include '../db/db_Connect.php';
$res1 = mysql_query("SELECT * from patients WHERE primary_disease='CHF' AND discharged_on IS NULL");
$nCHF= mysql_num_rows($res1);	

$res2= mysql_query("SELECT * from patients WHERE primary_disease ='Diabetes' AND discharged_on IS NULL");
$nDiabetes= mysql_num_rows($res2);										
include '../db/db_Close.php';

    // create the graph
    $Graph =& new Image_Graph(400, 300);

	// create the plotarea
	$Graph->add(
        new Image_Graph_Layout_Vertical(
            new Image_Graph_Title("", $Arial),
            $Plotarea = new Image_Graph_Plotarea(),
            5            
        )
    );
        
	// create the dataset
	$Dataset =& new Image_Graph_Dataset_Trivial();
	$Dataset->addPoint(1, $nCHF);
	$Dataset->addPoint(2, $nDiabetes);

$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    
	// create the plot as bar chart using the dataset
	$Plot =& $Plotarea->addPlot(new Image_Graph_Plot_Bar($Dataset));

$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
 $AxisX->setDataPreprocessor(
        new Image_Graph_DataPreprocessor_Array(
            array(
                1=>"CHF",
                2=>"Diabetes",
                3=> ""
            )
        )
    ); 
    $AxisX->setLabelInterval(1);
    
    $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $AxisY->setLabelInterval(1);

    // set a standard fill style
    $BLUE =& $Graph->newColor(IMAGE_GRAPH_BLUE, 100);
    $Plot->setFillStyle($BLUE);

    // add a TrueType font
    $Arial =& $Graph->addFont(new Image_Graph_Font_TTF("arial.ttf"));
    // set the font size to 15 pixels
    $Arial->setSize(11);
    // add a title using the created font
    $Graph->add(new Image_Graph_Title("Hospital Disase Distribution", $Arial));
    
    // output the Graph
    $Graph->done();
?>
